package com.atcjx.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 描述：配置文件上传路径
     * @author 崔杰翔
     * @Date 2021/9/27 19:11
     * @param null
     * @return
     */
    @Autowired
    PathConfig pathConfig;

    /**
     * 解决 swagger静态资源无法访问的问题
     *
     * @param registry 资源处理程序注册表
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/upload/md/**")
                .addResourceLocations("file:" + pathConfig.getMdFilePath());
        registry.addResourceHandler("/upload/img/**")
                .addResourceLocations("file:" + pathConfig.getImgFilePath());
    }

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 描述：拦截需要登录权限的请求
     * @author 崔杰翔
     * @Date 2021/9/26 20:05
     * @param registry
     * @return
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/auth/**");
    }
}
